<?php
namespace App\Service\PssService;

use App\Service\BaseService;
use App\Service\Code\Normal;
use App\Model\PssModel\Node;
use Hyperf\DbConnection\Db;
use App\Service\CacheService\CacheProviderService;

/**
 * 云仓菜单权限查询服务
 * @author chenyun
 */
class SystemCloudNodeService extends BaseService
{
    const CACHE_KEY = 'systemcloudnodeservice_query';

    /**
     * 查询云仓菜单权限明细
     * @param array $param            
     * @return mixed
     */
    public function querySystemCloudNodeList()
    {
        $list = CacheProviderService::instance()->getCacheByKey(self::CACHE_KEY);
        if( empty($list) ) 
        {
            $list = Node::instance()->select([
                'id',
                'pid',
                Db::raw("name as title"),
                Db::raw("node as jump"),
                'is_menu',
                'en_short'
            ])
            ->where('status',1)
            ->where('df',0)
            ->where('menu_type',1)
            ->orderBy('sort','asc')
            ->get()
            ->toArray();
            CacheProviderService::instance()->cacheBySetKeyValue(self::CACHE_KEY,$list);
        }
        return Normal::returnCode(Normal::SUC,"获取成功",$list);
    }

    /**
     * 查询指定权限接口明细
     * @param array $param            
     * @return mixed
     */
    public function querySystemNodesByInputs(array $param)
    {
        if( empty($param['nodes']) ) {
            return Normal::returnCode(Normal::FAIL,"nodes节点数据不能为空");
        }
        
        $nodes = $param['nodes'];
        $list = Node::instance()->select([
            'id',
            'pid',
            Db::raw("name as title"),
            Db::raw("node as jump"),
            'is_menu',
            'en_short'
        ])
        ->whereIn('en_short',$nodes)
        ->where('status',1)
        ->where('df',0)
        ->where('menu_type',1)
        ->orderBy('sort','asc')
        ->get()
        ->toArray();
        return Normal::returnCode(Normal::SUC,"获取成功",$list);
    }
}